package com.ptp.backendcertms.basiccompnents.data.dao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ptp.backendcertms.basiccompnents.data.dao.entity.ImportRecordPo;
import com.ptp.backendcertms.basiccompnents.data.dao.mapper.IImportRecordMapper;
import com.ptp.backendcertms.basiccompnents.data.dao.service.IImportRecordService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

import static com.ptp.backendcertms.api.internal.constant.DateTypeConstant.DATE_TIME_PATTERN_SHORT_MATTER;

/**
 * 导入数据记录模型 服务实现
 *
 * @author songcongcong
 * @date 2025/5/9
 */
@Service
public class ImportRecordServiceImpl extends ServiceImpl<IImportRecordMapper, ImportRecordPo> implements IImportRecordService {

    @Override
    public void saveImportRecord(ImportRecordPo entity) {
        entity.setCreateTime(LocalDateTime.now().format(DATE_TIME_PATTERN_SHORT_MATTER));
        save(entity);
    }

    @Override
    public ImportRecordPo getByBatchNo(String batchNo) {
        LambdaQueryWrapper<ImportRecordPo> lambdaQueryWrapper = Wrappers.lambdaQuery();
        lambdaQueryWrapper.eq(ImportRecordPo::getBatchNo, batchNo);
        return getOne(lambdaQueryWrapper);
    }
}
